using System;
using System.Collections.Generic;
using System.Text;
using JobShopModel.Model.FactoryLvl;
using JobShopModel.Model.Station;
using JobShopModel.Model;

namespace JobShopModel.Events
{
    /// <summary>
    /// Abstract Class:
    /// Represent all the Events involving a station 
    /// The station is in fact where the event take place
    /// </summary>
    abstract public class StationEvent:IEvent
    {
        private Time sTime;
        private StationsName stationName;

        #region property
        /// <summary>
        /// Property:
        /// Time the event must be excuted
        /// Read Only, must be set by the constructor of the implementation,
        /// Will be used to store the Event in the <seealso cref="EventQueue"/>
        /// </summary>
        public Time ExecTime
        {
            get
            {
                return this.sTime;
            }
        }


        /// <summary>
        /// Property:
        /// Name of the station
        /// </summary>
        public StationsName StationName
        {
            get
            {
                return this.stationName;
            }

        }

        /// <summary>
        /// Property:
        /// Operating Station returned from the factory
        /// </summary>
        public IStations OperatingStation
        {
            get
            {
                return Factory.getInstance().Stations[StationName];
            }
        }

        #endregion property

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="startTime">Starting time of the event</param>
        /// <param name="opStation">Operating station</param>
        protected StationEvent(Time startTime, StationsName opStation)
        {
            this.sTime = startTime;
            this.stationName = opStation;
        }

        /// <summary>
        /// Polymorphic method
        /// It will be instanced by all Events and excecuted by the eventloop
        /// </summary>
        public abstract void Process();

        /// <summary>
        /// Abstract method implemented for IComparable
        /// </summary>
        /// <param name="event1">First event</param>
        /// <param name="event2">Second event</param>
        /// <returns>1 if event1 occurs first, -1 if it occurs second, 0 otherwise</returns>
        public abstract int CompareTo(IEvent event1, IEvent event2);

        #region IEvent Membres


        public Logger Logger
        {
            get { return Logger.GetLogger(); }
        }

        #endregion

        #region IComparable<IEvent> Members

        /// <summary>
        /// Comparison function implemented as part of IComparable
        /// </summary>
        /// <param name="other">Event to compare this one to</param>
        /// <returns>1 if implicit occurs sooner, -1 if it occurs later, 0 otherwise</returns>
        public int CompareTo(IEvent other)
        {
            return this.ExecTime.CompareTo(other.ExecTime);
        }

        #endregion
    }
}
